package com.javasea.scene.repeatSubmit.example2.controller;

import com.javasea.scene.repeatSubmit.example2.lock.NoRepeatSubmit;
import com.javasea.scene.repeatSubmit.example2.lock.RedisLock;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 *@ClassName DemoController
 *@Description TODO
 *@Author longxiaonan@163.com
 *@Date 2020/11/29 0029 0:15
 */
@Slf4j
@RestController
public class DemoController {

    @Autowired
    private DemoService demoService;

    @Autowired
    private RedisLock redisLock;

    @GetMapping("/test")
    public void test() {
        log.warn("^^^^^^^^^^^^^^^^^^^^^^^^^");
        demoService.test();
        log.warn("vvvvvvvvvvvvvvvvvvvvvvvvvvvv");
    }

    @GetMapping("/test1")
//    @NoRepeatSubmit(scope = 1)
    public void test1() {
        log.warn("^^^^^^^^^^^^^^^^^^^^^^^^^");
        boolean b = redisLock.tryLock2("/aaaaaa", "1", 1800);
        if (b) {
            log.warn(">>>>>>>>执行业务");
            demoService.test();
            redisLock.releaseLock("/aaaaaa", "1");
        } else {
            log.warn("<<<<<<<<业务正在进行中，请稍后");
        }
        log.warn("vvvvvvvvvvvvvvvvvvvvvvvvvvvv");
    }

    @GetMapping("/test2")
    @NoRepeatSubmit(scope = 1)
    public void test2(Map<String, Object> paramMap) {
        System.out.println(paramMap);
        demoService.test2();
    }

}
